//
//  SPMacros.h
//  SPKit
//
//  Created by 李双鹏 on 15/10/6.
//  Copyright (c) 2015年 SP. All rights reserved.
//

#ifndef SPKit_SPMacros_h
#define SPKit_SPMacros_h //file

// Debugging / Logging
#ifdef DEBUG
    #ifndef SPLog
    #define SPLog(format, ...) \
    CFShow((__bridge void *)[NSString stringWithFormat:@"%s [LINE: %d] ==>> " format,__PRETTY_FUNCTION__, __LINE__, ## __VA_ARGS__]);
    #endif
#else
    #ifndef SPLog
    #define SPLog(format, ...)
    #endif
#endif


/**
 * UIColor Creation
 */
#ifndef ColorFromHex
#define ColorFromHex(hexValue) ColorFromHex_Alpha(hexValue,1.0)
#endif

#ifndef ColorFromHex_Alpha
#define ColorFromHex_Alpha(hexValue,Alpha) ([UIColor colorWithRed:((float)((hexValue & 0xFF0000) >> 16))/255.0f green:((float)((hexValue & 0xFF00) >> 8))/255.0f blue:((float)(hexValue & 0xFF))/255.0f alpha:Alpha])
#endif

#ifndef ColorFromHex
#define ColorFromHex(hexValue) (ColorFromHex_Alpha(hexValue, 1.0))
#endif

#ifndef ColorFromRGB
#define ColorFromRGB(Red,Green,Blue) ([UIColor colorWithRed:(Red)/255. green:(Green)/255. blue:(Blue)/255. alpha:1.])
#endif

#ifndef ThemeColor
#define ThemeColor ColorFromRGB(0, 204, 172)
#endif


/**
 * Screen Related
 */
#ifndef IS_IPAD
#define IS_IPAD ([[UIDevice currentDevice].model isEqualToString:@"iPad"])
#endif

#define IS_PORTRAIT ({BOOL b = NO; \
        if (@available(iOS 13.0, *)) { \
            b = UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].keyWindow.windowScene.interfaceOrientation); \
        }else{ \
            b = UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation); \
        } \
        b; \
    })

#define SCREEN_WIDTH ((IS_PORTRAIT) ? [UIScreen mainScreen].bounds.size.width : [UIScreen mainScreen].bounds.size.height)
#define SCREEN_HEIGHT ((IS_PORTRAIT) ? [UIScreen mainScreen].bounds.size.height : [UIScreen mainScreen].bounds.size.width)


#define DELTA_WIDTH (IS_IPAD ? (SCREEN_WIDTH / 1024.) : (SCREEN_WIDTH / 375.))
#define DELTA_HEIGHT (IS_IPAD ? (SCREEN_HEIGHT / 768.) : (SCREEN_HEIGHT / 667.))


/**
 * Weak Self
 */
#ifndef WEAKSELF

    #ifdef weakify
        #define WEAKSELF @weakify(self)
    #else
        #define WEAKSELF __weak typeof(self) weakSelf = self;
    #endif

#endif

/**
 * Strong Self
 */
#ifndef STRONGSELF

    #ifdef strongify
        #define STRONGSELF @strongify(self)
    #else
        #define STRONGSELF __strong typeof(self) strongSelf = weakSelf;
    #endif

#endif



#if ( __has_include("MBProgressHUD.h") || __has_include(<MBProgressHUD.h>) || __has_include("MBProgressHUD/MBProgressHUD.h") || __has_include(<MBProgressHUD/MBProgressHUD.h>) )

    #define ShowTips(tips) MBProgressHUD *tipsHud = [MBProgressHUD showHUDAddedTo:[[UIApplication sharedApplication] keyWindow] animated:YES]; \
    tipsHud.label.text = tips; \
    tipsHud.label.font = [UIFont mediumPingFangOfSize:scaleBase375(18)]; \
    tipsHud.label.numberOfLines = 10; \
    tipsHud.mode = MBProgressHUDModeText; \
    [tipsHud hideAnimated:YES afterDelay:1.5];
#else
    #define ShowTips(tips)
#endif


#endif // file
